package part3.c14_template;

/**
 * Created by lie on 2018/3/23.
 * 继承结构
 * 缺点就是，依赖（固定）这个排序方法
 * 万一要换一种排序方法，是做不到的
 */
public class IntegerBubbleSorter extends ABubbleSorter {

    private int[] arrays;

    public int sort(int[] arrays){
        this.length = arrays.length;
        this.arrays = arrays;
        return doSort();
    }

    protected boolean isNeedSwap(int index) {
        return arrays[index] > arrays[index+1];
    }

    protected void swap(int index) {
        int temp = arrays[index + 1];
        arrays[index+1] = arrays[index];
        arrays[index] = temp;
    }

}
